package com.gbits.app.finance.convert;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MultiDebitSubjectConvert extends DebitSubjectConvert {


	@Override
	public String doConvert(Map<String, Object> map) {
		StringBuffer sb = new StringBuffer();
		Map<String, Object> data = new HashMap<String, Object>();
		data.putAll(map);
		
		List<Map<String, Object>> subjectList = super.getSubjectList(map);
		// List<Map<String, Object>> taxSubject = super.getTaxList(map);
		double alltax = this.getAllTaxAmount(map);
		
		for (int i=0; i<subjectList.size(); i++) {
			Map<String, Object> subject = subjectList.get(i);
			data.putAll(subject);
			
			data.put("tax_amount", alltax);
			if (i == 0) {
				data.put("amount", Double.parseDouble(this.getAmount(map)) - alltax - (subjectList.size() - 1) * 1);
				data.put("no_tax_amount", Double.parseDouble(this.getAmount(map)) - alltax - (subjectList.size() - 1) * 1);
			} else {
				sb.append("\r\n");
				data.put("amount", 1);
				data.put("no_tax_amount", 1);
			}
			
			
			
			sb.append(super.doConvert(data));
		}
		
		
		return sb.toString();
	}

}
